#include "FontApp.h"

FontApp::FontApp()
{
}

FontApp::FontApp(HINSTANCE hInstance, std::string winCaption)
	:D3DApp(hInstance, winCaption, D3DDEVTYPE_HAL, D3DCREATE_HARDWARE_VERTEXPROCESSING)
{
	D3DXFONT_DESC fontDesc;
	fontDesc.Height = 80;
	fontDesc.Width = 40;
	fontDesc.MipLevels = 0;
	fontDesc.Italic = true;
	fontDesc.CharSet = DEFAULT_CHARSET;
	fontDesc.OutputPrecision = OUT_DEFAULT_PRECIS;
	fontDesc.Quality = DEFAULT_QUALITY;
	fontDesc.PitchAndFamily =  DEFAULT_PITCH | FF_DONTCARE;
	strcpy_s(fontDesc.FaceName, _T("Times New Roman"));

	HR(D3DXCreateFontIndirect(gD3DDevice, &fontDesc, &mFont));
}

FontApp::~FontApp()
{
	ReleaseCOM(mFont);
}

void FontApp::OnLostDevice()
{
	HR(mFont->OnLostDevice());
}

void FontApp::OnResetDevice()
{
	HR(mFont->OnResetDevice());
}

void FontApp::Update()
{

}

void FontApp::Draw()
{
	HR(gD3DDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255, 255, 255), 1.0f, 0));

	RECT fontRect;
	::GetClientRect(GetMainWindow(), &fontRect);

	HR(gD3DDevice->BeginScene());

	mFont->DrawText(0, _T("Hello Direct 3D!!!"), -1, &fontRect, DT_CENTER | DT_VCENTER,
		D3DCOLOR_XRGB(rand() % 256, rand() % 256, rand() % 256));

	HR(gD3DDevice->EndScene());

	HR(gD3DDevice->Present(0, 0, 0, 0));
}
